package com.ezjie.ielts.core.http;

import android.content.Context;
import android.content.Intent;

import com.alibaba.fastjson.JSON;
import com.ezjie.ielts.core.base.BaseBean;
import com.ezjie.ielts.db.UserInfoDB;
import com.ezjie.login.LoginActivity;
import com.ezjie.login.model.UserDetail;
import com.lidroid.xutils.exception.HttpException;

public abstract class HttpRequestAbstractCallBack implements HttpRequestCallBack {

	private Context context;
	private boolean isCheckLogin;

	public HttpRequestAbstractCallBack(Context context, boolean isCheckLogin) {
		this.context = context;
		this.isCheckLogin = isCheckLogin;
	}

	@Override
	public void onStartCallBack() {
		// TODO Auto-generated method stub

	}

	@Override
	public void onLoadingCallBack(long total, long current, boolean isUploading) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onSuccessCallBack(String result) {
		BaseBean bean = JSON.parseObject(result, BaseBean.class);
		if (isCheckLogin && !bean.getIs_login()) {
			UserInfoDB db = new UserInfoDB(context);
			UserDetail queryLoginUser = db.queryLoginUser();
			queryLoginUser.islogin = 0;
			db.update(queryLoginUser);
			context.startActivity(new Intent(context, LoginActivity.class));
			return;
		}

	}

	@Override
	public void onFailureCallBack(HttpException error, String msg) {

	}
}
